<template>
  <div v-if="hotCity">
    <!-- 热门城市 -->
    <div class="city-title">热门城市</div>
    <div class="hot-city-wrap">
      <div
        v-for="value in hotCity.cities"
        :key="value.cityId"
        class="hot-city-item"
        @click="chooseCity(value.name)"
      >
        {{ value.name }}
      </div>
    </div>

    <div v-for="item in otherCity" :key="item.prefix">
      <div class="city-title">{{ item.prefix.toUpperCase() }}</div>
      <div
        v-for="value in item.cities"
        :key="value.cityId"
        class="city-item"
        @click="chooseCity(value.name)"
      >
        {{ value.name }}
      </div>
    </div>
  </div>
</template>

<script>
import { mapMutations, mapActions, mapGetters } from "vuex";
export default {
  computed: {
    ...mapGetters("city", ["hotCity", "otherCity"]),
  },
  mounted() {
    this.asyncGetCityData();
  },
  methods: {
    chooseCity(name) {
      this.changeName({ name });
      this.$router.go(-1);
    },
    ...mapMutations("city", ["changeName"]),
    ...mapActions("city", ["asyncGetCityData"]),
  },
};
</script>

<style lang="less" scoped>
.city-title {
  padding-left: 0.5rem;
  line-height: 0.6rem;
  background-color: #ebebeb;
  font-size: 0.28rem;
  color: #333;
  height: 100%;
  width: 100%;
  z-index: 1000;
  overflow-y: auto;
}

.city-item {
  height: 0.88rem;
  line-height: 0.88rem;
  margin-left: 0.3rem;
  border-bottom: 0.02rem solid #c8c7cc;
  font-size: 16px;

  &:last-child {
    border: none;
  }
}

.hot-city-wrap {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-around;
  font-size: 16px;

  .hot-city-item {
    width: 28%;
    border: 1px solid #333;
    margin: 10px 0;
    text-align: center;
    line-height: 28px;
    background-color: #fff;
  }
}
</style>
